<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>系统用户</title>
	<link rel="stylesheet" type="text/css" href="easyui/themes/default/easyui.css">
	<link rel="stylesheet" type="text/css" href="easyui/themes/icon.css">
	<script type="text/javascript" src="easyui/jquery.min.js"></script>
	<script type="text/javascript" src="easyui/jquery.easyui.min.js"></script>
	<script type="text/javascript" src="easyui/locale/easyui-lang-zh_CN.js"></script>
	<script type="text/javascript">
		//工具栏
		var toolbar = [{
			text: '新增',
			iconCls: 'icon-add',
			handler: function () {
				$('#dd').dialog('open');
			}
		}, {
			text: '修改',
			iconCls: 'icon-edit',
			handler: function () {
				var row = $('#managerlist').datagrid("getSelected");
				if (row == null) {
					$.messager.alert('提示', '请先选择要修改的用户！', 'info');
					return;
				}
				$('#dd_modify').dialog('open');
				$.ajax({
					url: 'http://localhost:8080/exchange/managers/findById',
					method: 'post',
					data: {id: row.id},
					type: 'json',
					success: function(result){
						if (result.code ==500){
							alter(result.msg);
						}
						$('#username_modify').textbox('setValue',result.data.username);
						$('#nickname_modify').textbox('setValue',result.data.nickname);
					}
				})

			}
		}, {
			text: '删除',
			iconCls: 'icon-no',
			handler: function () {
				 $.messager.confirm('系统提示', '确定要删除该用户吗？', function (r) {
					if (r) {
						let row = $('#managerlist').datagrid("getSelected");
						$.ajax({
							url: "http://localhost:8080/exchange/managers/deleteUser",
							data:{id: row.id},
							dataType: 'json',
							method: 'get',
							success: function(result){
								if (result.code != 200){
									alter(result.msg);
								};
								$("#managerlist").datagrid("reload");
							},
							error: function(){
								alter("ajax请求异常");
							}

						});

						$.messager.alert('提示','删除成功','info');
					}
				});
			}
		}, {
			text: '初始化密码',
			iconCls: 'icon-reload',
			handler: function () {
				$.messager.confirm('系统提示', '确定要初始化该用户密码吗？', function (r) {
					if (r){


					}
				});
			}
		}];

		$(function () {
			$('#managerlist').datagrid({
				url:'http://localhost:8080/exchange/managers/findByPage',
				method: 'get',
				title: '系统用户列表',
				iconCls: 'icon-save',
		
				columns: [[
					{ field: 'id', title: '用户ID', width: '25%', align: 'center' },
					{ field: 'nickname', title: '用户姓名', width: '25%', align: 'center' },
					{ field: 'username', title: '登陆账号', width: '25%', align: 'center' },
					{ field: 'password', title: '登陆密码', width: '25%', align: 'center' }
				]],
				width: '100%',
				singleSelect: true,
				rownumbers: true,
				pagination: true,
				pageSize:5,
                pageList:[5,10,30],
				toolbar: toolbar
			});

			//初始化添加窗口  
			$('#dd').dialog({
				title: '添加用户',
				width: 400,
				closed: true,
				cache: false,
				href: '',
				modal: true,
				iconCls: 'icon-save',
				buttons: [{
					text: '提交',
					iconCls: 'icon-ok',
					handler: function () {
						addUser();
						$('#dd').dialog('close');
					}
				}, {
					text: '关闭',
					iconCls: 'icon-no',
					handler: function () {
						$('#dd').dialog("close");
					}
				}]
			});
			


			// 初始化修改窗口
			$('#dd_modify').dialog({
				title: '修改用户',
				width: 400,
				closed: true,
				cache: false,
				href: '',
				modal: true,
				iconCls: 'icon-save',
				buttons: [{
					text: '提交',
					iconCls: 'icon-ok',
					handler: function () {
						modifyUser();
						$('#dd_modify').dialog('close');
					}
				}, {
					text: '关闭',
					iconCls: 'icon-no',
					handler: function () {
						$('#dd_modify').dialog("close");
					}
				}]
			});

			function addUser(){
				let param=$('#ff_user_add').serializeArray();
				$.ajax({
					url: 'http://localhost:8080/exchange/managers/addUser',
					method:'post',
					dataType: 'json',
					data: param,
					success: function(result){
						if(result.code==500){
							alter(result.msg);
						}
						$('#managerlist').datagrid('reload');
					},
					error: function(){
						alter('请求或响应异常');
					}
					
				})
			};

			function modifyUser(){
				let param = $('#ff_user_modify').serializeArray();
				$.ajax({
					url: 'http://localhost:8080/exchange/managers/modifyUser',
					data: param,
					method: 'get',
					dataType: 'json',
					success: function(result){
						if (result.code == 500){
							alter(result.msg);
						}
						$('#managerlist').datagrid('reload');
					}
				})
			};


			
		});
	</script>
</head>

<body>
	<table id="managerlist"></table>

	<div id="dd">
		<div style="text-align: center;margin-top: 30px;">
			<form id="ff_user_add" method="post">
				<div style="margin-bottom:30px">
					<input class="easyui-textbox" id="username_add" name="username_add" style="width:60%;height: 30px;"
						data-options="label:'用户姓名:',required:true" />
				</div>
				<div style="margin-bottom:30px">
					<input class="easyui-textbox" id="nickname_add" name="nickname_add" style="width:60%;height: 30px;"
						data-options="label:'登录账号:',required:true">
				</div>
			</form>
		</div>
	</div>

	<div id="dd_modify">
		<div style="text-align: center;margin-top: 30px">
			<form id="ff_user_modify" method="post">
				<input id="modify_id" type="hidden">
				<div style="margin-bottom:30px">
					<input class="easyui-textbox" id="username_modify" name="username_modify" style="width:60%;height: 30px;"
						data-options="label:'用户姓名:',required:true" />
				</div>
				<div style="margin-bottom:30px">
					<input class="easyui-textbox" id="nickname_modify" name="nickname_modify" style="width:60%;height: 30px;"
						data-options="label:'登陆账号:',required:true">
				</div>
			</form>
		</div>
	</div>
</body>
</html>